﻿using System;
using System.Collections.Generic;
using Wedn.Core.Common;
using Wedn.Core.Entity;
using Wedn.Core.Service;
using Wedn.Core.Utility;
using Wedn.TemplateEngine.UC;

namespace Wedn.Web.UI
{
    public class WidgetBase : Template
    {
        ///// <summary>
        ///// 链接集合;
        ///// </summary>
        //public List<Link> links;
        ///// <summary>
        ///// 根据指定类型获取指定集合
        ///// </summary>
        ///// <param name="type">类型名称</param>
        //public void LoadLinks(string type)
        //{
        //    links = LinkManager.GetLinkList(type, true);
        //}
        PostManager postManager = new PostManager();
        /// <summary>
        /// 按照发布时间降序排列前几条文章信息, 返回对象集合
        /// </summary>
        public List<Post> RecentPosts
        {
            get
            {
                int count = StringHelper.StrToInt(Setting.Dict["RecentPostsCount"].ToString(), 8);
                return postManager.GetPostList(PostStatus.Pubilc, PostType.Post, count, 1, "post_pubdate", 0);
            }
        }

        /// <summary>
        /// 按照发布时间降序排列前几条文章信息, 返回对象集合
        /// </summary>
        public List<Archive> Archives
        {
            get
            {
                int count = StringHelper.StrToInt(Setting.Dict["RecentPostsCount"].ToString(), 8);
                return postManager.GetArchiveList();
            }
        }


        LinkManager linkManager = new LinkManager();
        /// <summary>
        /// 友情链接集合
        /// </summary>
        public List<Link> Blogroll
        {
            get
            {
                return linkManager.GetLinkList(0, LinkType.Blogroll, true);
            }
        }
        TermManager termManager = new TermManager();
        /// <summary>
        /// 标签集合
        /// </summary>
        public List<Term> Tag
        {
            get
            {
                return termManager.GetTermList(TermType.PostTag);
            }
        }

        /// <summary>
        /// 分类集合
        /// </summary>
        public List<Term> Category
        {
            get
            {
                return termManager.GetTermList(TermType.PostCategory);
            }
        }

        /// <summary>
        /// 随机样式
        /// </summary>
        public string RandomStyle
        {
            get
            {
                return "randomstyle" + GetRandom(1, 10);
            }
        }


        Random random = null;
        /// <summary>
        /// 获取随机数
        /// </summary>
        public int GetRandom(int minNum, int maxNum)
        {
            return random.Next(minNum, maxNum);
        }
    }
}
